<?php
if(!class_exists('MAIN_Controller_Action')) Zend_Loader :: loadClass('MAIN_Controller_ActionFront');
class Front_TransectionController extends MAIN_Controller_ActionFront {
    public function patransectionAction() {
    	$view = $this->_getView();
    	$today = getToday();
    	$view->assign("today",$today);
    	$view->assign("defaultdate",date('d/m/Y'));
    	$view->output('transection/pa_transection.tpl');
    }
    public function loadtplAction(){
    	$params   = $this->getParams();
    	$view = $this->_getView();
    	$view->output('transection/'.$params['tpl'].'.tpl');
    }
    public function getpreauthtranlistAction() {
    	$params   = $this->getParams();
    	$generic = $this->getGeneric();
    	$view = $this->_getView();
    	if(!class_exists('Zend_Auth'))Zend_loader :: loadClass('Zend_Auth');
    	$auth = Zend_Auth :: getInstance();
    	$identity = $auth->getIdentity();
    	$data = $generic->getpreauthtranlist($params,$identity->userid);

    	foreach ($data as $key=>$value){
    		if(trim($data[$key]['preauth_status']) == 'p'){
    			$data[$key]['preauth_status'] = "<font color='green'>Payment แล้ว</font> ";
    		}else{
    			$data[$key]['preauth_status'] = "<font color='red'>รอ Payment</font> ";
    		}
    	}

    	$view->assign("data",$data);
    	$data['htmls'] = $view->outputhtml('ajax/_view_pa_tran_list.tpl');
    	$this->_helper->json($data);
    }
    public function paymenttransectionAction() {
    	$view = $this->_getView();
    	$today = getToday();
    	$view->assign("today",$today);
    	$view->assign("defaultdate",date('d/m/Y'));
    	$view->output('transection/payment_transection.tpl');
    }
    public function getpaymenttranlistAction() {
    	$params   = $this->getParams();
    	$generic = $this->getGeneric();
    	$view = $this->_getView();
    	if(!class_exists('Zend_Auth'))Zend_loader :: loadClass('Zend_Auth');
    	$auth = Zend_Auth :: getInstance();
    	$identity = $auth->getIdentity();
    	$data = $generic->getpaymenttranlist($params,$identity->userid);
    	
    	foreach ($data as $key=>$value){
    		$data[$key]['charge'] = number_format($data[$key]['charge'],2,'.',',');
    		$data[$key]['pre_approved'] = number_format($data[$key]['pre_approved'],2,'.',',');
    	}
    	
    	$view->assign("data",$data);
    	$data['htmls'] = $view->outputhtml('ajax/_view_payment_tran_list.tpl');
    	$this->_helper->json($data);
    }
    public function preauthdetailAction(){
    	$params   = $this->getParams();
    	$generic = System_Controller::getGeneric("preauthorize","front");
    	$view = $this->_getView();
    	$today = getToday();
    	$preauthId = $generic->getPreauthId();
    	$policyData = $generic->getPolicyById($params['policy_id']);
    	$paInfo = $generic->getPaInfo($params['policy_id']);
    	$paClaimData = $generic->getPaClaim($params['policy_id']);
    	if($policyData['customer_type_desc'] == 'PA'){
    		$tpl = 'preauthorize/pa_detail.tpl';
    	}
    	else{
    		$erClaimData = $generic->getErClaim($params['policy_id']);
    		$PlanData = $generic->getPlan2catByPlanId($policyData['plan_id'],$params['policy_id']);
    		$PlanData['opd'] = number_format($PlanData['opd'],2,'.',',');
    		$PlanData['rb'] = number_format($PlanData['rb'],2,'.',',');
    		$PlanData['er'] = number_format($PlanData['er'],2,'.',',');
    		$view->assign("erClaimData",$erClaimData);
    		$view->assign("PlanData",$PlanData);
    		$tpl = 'preauthorize/health_detail.tpl';
    	}
    	$view->assign("APP_URL",APP_URL);
    	$view->assign("policy_id",$params['policy_id']);
    	$view->assign("today",$today);
    	$view->assign("preauthId",$preauthId);
    	$view->assign("policyData",$policyData);
    	$view->assign("paInfo",$paInfo);
    	$view->assign("paClaimData",$paClaimData);
    	$view->assign("title",'Pre-authorize Transection');
    	$view->output($tpl);
    }
    public function paymentpaAction(){
    	if(!class_exists('Zend_Auth'))Zend_loader :: loadClass('Zend_Auth');
    	$params   = $this->getParams();
    	$generic = $this->getGeneric();
    	$payment_generic = System_Controller::getGeneric("payment","front");
    	$view = $this->_getView();
    	$today = getToday();
    	$payment_datetime	=	date('Y-m-d H:i:s');
    	$auth = Zend_Auth :: getInstance();
    	$identity = $auth->getIdentity();
    	$payment_detail = $generic->getPaymentDetail($params['payment_id']);
    	$preauthData = $payment_generic->getPreAuthById($payment_detail['preauth_id'],$identity->userid);
    	$policyData = $payment_generic->getPolicyById($preauthData['0']['policyid']);   	
    	$claimGetCover	=	$payment_generic->getClaimCover();
    	
    	// Accident Date
    	$ac_day	=	explode(" ",$payment_detail['acc_date']);
    	$ac_dmy	= 	explode("-",$ac_day[0]);
    	$ac_d	=	$ac_dmy[2];
    	$ac_m	=	$ac_dmy[1];
    	$ac_y	=	$ac_dmy[0]+543;
    	 
    	$ac_time 		= 	explode(".",$ac_day[1]);
    	$ac_time1	=	$ac_time[0];
    	$ac_time2	=	$ac_time[1];
    	$ac_t				=	explode(":",$ac_time[0]);
    	$ac_hour		=	$ac_t[0];
    	$ac_min		=	$ac_t[1];
    	$ac_lastacc	=	$ac_hour.":".$ac_min;
    	
    	$ac_al	= $ac_d."/".$ac_m."/".$ac_y." ".$ac_lastacc	;
    	
    	// Accident Date
    	$ad_day	=	explode(" ",$payment_detail['admis_date']);
    	$ad_dmy	= 	explode("-",$ad_day[0]);
    	$ad_d	=	$ad_dmy[2];
    	$ad_m	=	$ad_dmy[1];
    	$ad_y	=	$ad_dmy[0]+543;
    	
    	$ad_time 		= 	explode(".",$ad_day[1]);
    	$ad_time1	=	$ad_time[0];
    	$ad_time2	=	$ad_time[1];
    	$ad_t				=	explode(":",$ad_time[0]);
    	$ad_hour		=	$ad_t[0];
    	$ad_min		=	$ad_t[1];
    	$ad_lastacc	=	$ad_hour.":".$ad_min;
    	 
    	$ad_al	= $ad_d."/".$ad_m."/".$ad_y." ".$ad_lastacc	;
    	
    	$policyData['deductible'] = number_format($policyData['deductible'],2,'.',',');
    	$policyData['copayment'] = number_format($policyData['copayment'],2,'.',',');
    	
    	$payment_detail['charge'] = number_format($payment_detail['charge'],2,'.',',');
    	$payment_detail['discount'] = number_format($payment_detail['discount'],2,'.',',');
    	$payment_detail['deductible'] = number_format($payment_detail['deductible'],2,'.',',');
    	$payment_detail['copayment'] = number_format($payment_detail['copayment'],2,'.',',');
    	$payment_detail['pre_approved'] = number_format($payment_detail['pre_approved'],2,'.',',');
    	$payment_detail['non_covered'] = number_format($payment_detail['non_covered'],2,'.',',');
    	
    	if($policyData['deductible'] == '0.00')	$policyData['deductible'] = '';
    	if($policyData['copayment'] == '0.00')	$policyData['copayment'] = '';
    	 
    	//_print($policyData); exit(); //--beerz
    	
    	$img = 'title_pa.png';
    	$view->assign("img",$img);
    	$view->assign("APP_URL",APP_URL);
    	$view->assign("paymentId",$params['payment_id']);
    	$view->assign("preauthData",$preauthData['0']);
    	$view->assign("today",$today);
    	$view->assign("payment_datetime",$payment_datetime);
    	$view->assign("policyData",$policyData);
    	$view->assign("claimGetCover",$claimGetCover);
    	$view->assign("payment_detail",$payment_detail);
    	$view->assign("ac_al",$ac_al);
    	$view->assign("ad_al",$ad_al);
    	$view->assign("title",'Payment Transection');
    	$view->output('transection/payment_pa.tpl');
    }
}
?>